package com.cykj.pos.service.impl;

import com.cykj.common.core.domain.AjaxResult;
import com.cykj.pos.domain.BizTransferRecordsDetail;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.StringUtils;
import com.cykj.pos.mapper.BizTransferRecordsMapper;
import com.cykj.pos.domain.BizTransferRecords;
import com.cykj.pos.service.IBizTransferRecordsService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 划拨记录Service业务层处理
 *
 * @author Zephyr
 * @date 2025-05-29
 */
@Service
public class BizTransferRecordsServiceImpl extends ServiceImpl<BizTransferRecordsMapper, BizTransferRecords> implements IBizTransferRecordsService {

    @Resource
    private BizTransferRecordsMapper bizTransferRecordsMapper;

    @Override
    public List<BizTransferRecords> queryList(BizTransferRecords bizTransferRecords) {
        LambdaQueryWrapper<BizTransferRecords> lqw = Wrappers.lambdaQuery();
        if (StringUtils.isNotBlank(bizTransferRecords.getType())){
            lqw.eq(BizTransferRecords::getType ,bizTransferRecords.getType());
        }
        if (bizTransferRecords.getTransferTime() != null){
            lqw.eq(BizTransferRecords::getTransferTime ,bizTransferRecords.getTransferTime());
        }
        if (StringUtils.isNotBlank(bizTransferRecords.getReceiver())){
            lqw.like(BizTransferRecords::getReceiver ,bizTransferRecords.getReceiver());
        }
        if (StringUtils.isNotBlank(bizTransferRecords.getChannel())){
            lqw.eq(BizTransferRecords::getChannel ,bizTransferRecords.getChannel());
        }
        lqw.orderByDesc(BizTransferRecords::getTransferTime);
        List<BizTransferRecords> list= this.list(lqw);
        list.forEach(e->{
            if("1".equals(e.getChannel())){
                e.setChannel("乐刷");
            }else if("2".equals(e.getChannel())){
                e.setChannel("拉卡拉");
            }else if("15".equals(e.getChannel())){
                e.setChannel("盛付通");
            }else if("16".equals(e.getChannel())){
                e.setChannel("星驿付");
            }else if("17".equals(e.getChannel())){
                e.setChannel("嘉联");
            }
        });
        return list;
    }

    @Override
    public AjaxResult queryDetailShow(BizTransferRecords bizTransferRecords) {
        AjaxResult ajaxResult = AjaxResult.success("明细");
        List<BizTransferRecordsDetail> list = bizTransferRecordsMapper.queryDetailShow(bizTransferRecords);
        ajaxResult.put("total",list.size());
        ajaxResult.put("data",list);
        return ajaxResult;
    }
}
